/************************************************************************
 * @file StandardContentPanelManager.cpp
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#include <QTabWidget>

#include <pluginui/manager/spi/StandardContentPanelManager.h>

namespace antu
{
namespace plugin
{
namespace ui
{
StandardContentPanelManager::StandardContentPanelManager(QMainWindow* pMainWindow)
    : AbstractPanelManager(),
      m_pMainWindow(pMainWindow)
{
    Q_ASSERT(pMainWindow != nullptr);
}

void StandardContentPanelManager::finalize()
{
    size_t count = this->m_oPanels.size();

    if (count == 1)
    {
        this->m_pMainWindow->setCentralWidget(this->m_oPanels[0]->containerWidget());
    }
    else if (count > 1)
    {
        QTabWidget* pWidget = new QTabWidget(this->m_pMainWindow);
        pWidget->setTabsClosable(false);
        auto iter = this->m_oPanels.begin();
        auto end = this->m_oPanels.end();

        for (; iter != end; iter++)
        {
            (*iter)->finalize();
            QWidget* pChildWidget = (*iter)->containerWidget();

            if (pChildWidget->windowIcon().isNull())
            {
                pWidget->addTab(pChildWidget, pChildWidget->windowTitle());
            }
            else
            {
                pWidget->addTab(pChildWidget, pChildWidget->windowIcon(), pChildWidget->windowTitle());
            }
        }
        this->m_pMainWindow->setCentralWidget(pWidget);
    }
}

void StandardContentPanelManager::createContainer(AbstractPanelContainer* /*pContainer*/,
                                                  Qt::DockWidgetArea /*area*/,
                                                  Qt::DockWidgetAreas /*allowedAreas*/,
                                                  QDockWidget::DockWidgetFeatures /*features*/)
{

}

}
}
}

